///<reference path="../types/advanced.d.ts" />
///<reference path="../types/util.d.ts" />


type Person = {name:string, age:number}
let pluck:IPluck<Person, 'age'>
let pluck2:IPluck2

pluck = function(o, names) {
  return names.map(n => o[n]);
}
pluck2 = function(o, names) {
  return names.map(n => o[n]);
}

pluck({name:'vincent',age:40},['age'])

let obj = { a: 1, b: '2', c: false };
pluck2(obj, ['a','c']);

let arr:Array<string>  = ['a','b']

//type ReplaceValByOwnKey<T, S extends any> = { [P in keyof T]: S[P] };

let replaceValByAny:ReplaceValByOwnKey<Person,any> = {
 name:'afef',
 age:true
}

//如果S[P] 不存在，可以任意类型
let replaceValByBool:ReplaceValByOwnKey<Person,boolean> ={
  name:'afef',
  age:30 
}

//如果S[P] 存在，则必须是S[P]的类型
type CatType = {name:'cat',age:3}
let replaceValByObj:ReplaceValByOwnKey<Person, CatType> = {
  name:'cat',
  age:3
}


let functionWithProp:FunctionWithProperty = function(name){

}
functionWithProp.age = 'aefefe'

//type ShiftAction<T extends any[]> = ((...args: T) => any) extends ((arg1: any, ...rest: infer R) => any) ? R : never;

type key = 'vue' | 'react';

type MappedType<T extends key> = { [k in key]: T } // { vue: string; react: string; }

interface bb<T extends string>{
  [p: string]: string 
}

let arr2 = Array(5).join('#')
console.info(JSON.stringify(arr2))